package com.example.armmvvm.ui.constraint

import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.LifecycleOwner
import com.example.arm.ext.dpInt
import com.example.armmvvm.R
import com.example.armmvvm.databinding.LayoutNormalFallView2Binding
import com.example.armmvvm.ui.fallview.AnchorFallView
import com.example.armmvvm.ui.fallview.AnchorFallViewSetting
import com.example.armmvvm.ui.fallview.FallViewMode

/**
 * @author 创建人 ：yanghaozhang
 * @version 1.0
 * @package 包名 ：com.example.armmvvm.ui.constraint
 * @createTime 创建时间 ：2021/8/9
 * @modifyBy 修改人 ：
 * @modifyTime 修改时间 ：
 * @modifyMemo 修改备注：
 */
class NormalFallView2(private val count: Int, lifecycleOwner: LifecycleOwner, viewContainer: ViewGroup) :
    AnchorFallView(lifecycleOwner, viewContainer, R.layout.layout_normal_fall_view2) {
    override fun updateView(view: View) {
        LayoutNormalFallView2Binding.bind(view).apply {
            if (count < 10) {
                tvNext.setOnClickListener {
                    NormalFallView(count + 1, lifecycleOwner, viewContainer).show()
                }
            }
            if (count > 0) {
                tvLast.setOnClickListener {
                    NormalFallView(count - 1, lifecycleOwner, viewContainer).show()
                }
            }
            tvCount.text = count.toString()
            tvDismiss.setOnClickListener {
                dismiss()
            }
        }
    }

    override fun bottomFallViewSetting(view: View): AnchorFallViewSetting? {
        return AnchorFallViewSetting(view).apply {
            mode = FallViewMode.TWO_STATE
            calcHeight = {
                peekHeight = 380.dpInt
                anchorHeight = peekHeight
            }
        }
    }
}